# @Filename:    draw.py
# @Author:      王佳伟
# @Time:        2025-07-17 10:15
# @Describe:    绘图
import pandas as pd
import numpy as np
import matplotlib

matplotlib.use('TkAgg')     # 交互式（Tkinter

import matplotlib.pyplot as plt

# df = pd.DataFrame(np.random.randn(8, 4), index=pd.date_range('2/1/2020',periods=8),columns=list('ABCD'))
# df.plot()
# plt.show()

# 柱状图
# df = pd.DataFrame(np.random.rand(10, 5), columns=['a','b','c','d','e'])
# df.plot(kind = "bar")
# df.plot(kind = "bar", stacked = True) # 柱状堆叠图
# df.plot(kind = "barh", stacked = True)
# plt.show()

# 直方图
# df = pd.DataFrame({'A':np.random.randn(100) + 2, 'B':np.random.randn(100), 'C':np.random.randn(100) - 2}, columns=['A','B','C'])
# print(df)
# 指定箱数为15
# df.plot.hist(bins = 15)

# df = pd.DataFrame({'A':np.random.randn(100)+2,'B':np.random.randn(100),'C':np.random.randn(100)-2,'D':np.random.randn(100)+3},columns=['A', 'B', 'C','D'])
# 使用diff绘制，每一列数据都绘制一个直方图
# df.diff().hist(color="r", alpha=0.5, bins=15)

# 箱型图
# df = pd.DataFrame(np.random.rand(10, 4), columns=['A', 'B', 'C', 'D'])
# df.plot.box()

# 区域图
# df = pd.DataFrame(np.random.rand(5, 4), columns=['a', 'b', 'c', 'd'])
# df.plot().area()

# 散点图
# df = pd.DataFrame(np.random.rand(30, 4), columns=['a', 'b', 'c', 'd'])
# df.plot.scatter(x='a',y='b')

# 饼状图
df = pd.DataFrame(3 * np.random.rand(4), index=['go', 'java', 'c++', 'c'], columns=['L'])
print(df)
df.plot.pie(subplots=True)

plt.show()

